You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This adds mypy to the dev-requirements and also integrates it into the pre-commit configuration. Mypy is configured to only check library code, but not the tests. Mypy is used in strict mode. Finally we now distribute the package type information (according to pep 561).
Most of the adjustments were done on behalf of CoPilot, but checked in detail on my own.
I don't see any problems, the code changes are small and should make the code more robust.
But I would suggest to drop Python 3.9. It is EOL since almost a year and with 3.10 and up you can use the builtin union types like str | None instead of Optional[str]. I think it's the preferred way today. It's a bit easier to read and you don't need the imports. What do you think?
Hi @flabbamann
many thanks for your reply 🙂
I wouldn't drop python 3.9 in this PR, but we can already make use of the annotation future statement and those use the modern style annotations all over the library. I'll work on it.
_fritz is actually None whenever the public constructor is called without fritz, but this cast tells strict mypy it is always a valid Fritzhome. Subclass methods then dereference it without checks, so the newly published typing hides a real runtime state instead of modeling it. Please make _fritz optional and guard those methods, or require a Fritzhome for objects that expose remote operations.
Reject empty login challenges
pyfritzhome/fritzhome.py:245
An empty <Challenge/> is also unusable but is not caught by this None check; it falls through to the MD5 path and sends a response derived from an empty challenge instead of reporting the malformed login response. Reject empty strings as well.
Ensure getter colors are non-optional and setter-compatible
pyfritzhome/fritzhome.py:500
This return type is incompatible with the documented set_color() workflow: get_colors() produces Sequence[str | None], while set_color() accepts only Sequence[str | SupportsInt]. Strictly typed clients therefore cannot pass a returned color to the setter, and widening the setter would be unsafe because it calls int() on the values. Validate/filter missing XML attributes and expose non-optional color tuples in both public layers.
Normalize missing color temperatures before exposing them
pyfritzhome/fritzhome.py:540
get_color_temps() now returns list[str | None], but set_color_temp() rejects None, so a value obtained from the getter cannot be passed to the setter under strict typing. Since the setter also executes int(temperature), normalize or reject missing value attributes here and publish list[str] consistently through the device wrapper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds mypy to the dev-requirements and also integrates it into the pre-commit configuration. Mypy is configured to only check library code, but not the tests. Mypy is used in strict mode. Finally we now distribute the package type information (according to pep 561).
Most of the adjustments were done on behalf of CoPilot, but checked in detail on my own.